import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'exposureAnalysisM',
  state: {
    columns: [
      {
        title: '资产代码',
        dataIndex: 'assetsCode',
        key: 'assetsCode',
        display: true,
      },
      {
        title: '资产名称',
        dataIndex: 'assestsName',
        key: 'assestsName',
        display: true,
      },
      {
        title: '市值因子暴露度',
        dataIndex: 'markFactorExposure',
        key: 'markFactorExposure',
        sorter: (a, b) => a.markFactorExposure - b.markFactorExposure,
        display: true,
      },
      {
        title: 'BETA因子暴露度',
        dataIndex: 'BETAFactorExposure',
        key: 'BETAFactorExposure',
        sorter: (a, b) => a.BETAFactorExposure - b.BETAFactorExposure,
        display: true,
      },
      {
        title: '动量因子暴露度',
        dataIndex: 'momentumFactorExposure',
        key: 'momentumFactorExposure',
        sorter: (a, b) => a.momentumFactorExposure - b.momentumFactorExposure,
        display: true,
      },
      {
        title: '残余波动因子暴露度',
        dataIndex: 'residualFactorExposure',
        key: 'residualFactorExposure',
        sorter: (a, b) => a.residualFactorExposure - b.residualFactorExposure,
        display: true,
      },
      {
        title: '非线性市值因子暴露度',
        dataIndex: 'nonLinearFactorExposure',
        key: 'nonLinearFactorExposure',
        sorter: (a, b) => a.nonLinearFactorExposure - b.nonLinearFactorExposure,
        display: true,
      },
      {
        title: '价值因子暴露度',
        dataIndex: 'valueFactorExposure',
        key: 'valueFactorExposure',
        sorter: (a, b) => a.valueFactorExposure - b.valueFactorExposure,
        display: true,
      },
      {
        title: '流动因子暴露度',
        dataIndex: 'flowFactorExposure',
        key: 'flowFactorExposure',
        sorter: (a, b) => a.flowFactorExposure - b.flowFactorExposure,
        display: true,
      },
      {
        title: '盈利因子暴露度',
        dataIndex: 'profitFactorExposure',
        key: 'profitFactorExposure',
        sorter: (a, b) => a.profitFactorExposure - b.profitFactorExposure,
        display: true,
      },
      {
        title: '成长因子暴露度',
        dataIndex: 'growthFactorExposure',
        key: 'growthFactorExposure',
        sorter: (a, b) => a.growthFactorExposure - b.growthFactorExposure,
        display: true,
      },
      {
        title: '杠杆因子暴露度',
        dataIndex: 'leverFactorExposure',
        key: 'leverFactorExposure',
        sorter: (a, b) => a.leverFactorExposure - b.leverFactorExposure,
        display: true,
      },
    ],
    checkedKeysInfo: [
      'assetsCode',
      'assestsName',
      'markFactorExposure',
      'BETAFactorExposure',
      'momentumFactorExposure',
      'residualFactorExposure',
      'nonLinearFactorExposure',
      'valueFactorExposure',
      'flowFactorExposure',
      'profitFactorExposure',
      'growthFactorExposure',
      'leverFactorExposure',
    ],
  },
  effects: {
    // 获取个股风格因子暴露度表格数据
    *getTableDate({ payload, callback }, { call, put }) {
      // const response = yield call(api.exposureAnalysis.getTableDate, payload);
      const response = {};
      if (response && response.code == 0) {
        callback(response.data.dataSource);
      } else {
        callback();
        // message.error(response?.msg || '获取个股风格因子暴露度表格数据失败！');
      }
    },
    // 风格因子暴露度
    *getFactorExposureStyle({ payload, callback }, { call, put }) {
      const res = yield call(api.exposureAnalysis.getFactorExposureStyle, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },
    // 行业因子暴露度
    *getFactorExposureIndustry({ payload, callback }, { call, put }) {
      const res = yield call(api.exposureAnalysis.getFactorExposureIndustry, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
